package com.han.hotelplat.cms.controller.datacenter.hotel;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.han.hotelplat.comm.ResponseWrapTo;
import com.han.hotelplat.comm.utils.DateUtil;
import com.han.hotelplat.service.datacenter.hotel.HotelDataService;

/**
 * 
	 ***************************************************************
	 * <p>
	 * @CLASS				:	CMSDataHotelController
	 * @DESCRIPTION	:	
	 * @AUTHOR				:	han1088
	 * @VERSION			:	v1.0
	 * @DATE					:	2018年10月29日 下午5:34:49            
	 * </p>
	 * 
	 * <p>
	 * @MODIFY	LOG	:		
	 * @AUTHOR				:	han1088
	 * @VERSION			:	v1.0
	 * @MODIFY DATE	:	
	 * </p>    
	 ****************************************************************
 */

@Controller
@RequestMapping("/cms/datacenter/hotel")
public class CMSDataHotelController {
	@Autowired
	private HotelDataService hotelDataService;
	
	/**
	 * 获取酒店数据按状态分类
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelDataByState", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET, RequestMethod.POST })
	public String getHotelDataByState(){
		Map<String, Integer> totalData = hotelDataService.getHotelDataByState();
		return new ResponseWrapTo(0, "数据获取成功", totalData).toJson();
	}
	
	/**
	 * 获取酒店数据按区域分类
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelDataByArea", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET, RequestMethod.POST })
	public String getHotelDataByArea(Integer groupArea){
		List<Map<String, Object>> totalData = hotelDataService.getHotelDataByArea(groupArea);
		return new ResponseWrapTo(0, "数据获取成功", totalData).toJson();
	}
	
	/**
	 * 获取酒店数据按星级分类
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelDataByHoteType", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET, RequestMethod.POST })
	public String getHotelDataByHoteType(){
		Map<String, Integer> totalData = hotelDataService.getHotelDataByHoteType();
		return new ResponseWrapTo(0, "数据获取成功", totalData).toJson();
	}
	
	/**
	 * 获取酒店日新增数据
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getNewHotelDataGroupDate", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET, RequestMethod.POST })
	public String getNewHotelDataGroupDate(String startTime, String endTime, Integer areaCode){
		if(StringUtils.isBlank(startTime)){
			return new ResponseWrapTo(-1, "请输入起始日期", null).toJson();
		}
		if(StringUtils.isBlank(endTime)){
			return new ResponseWrapTo(-1, "请输入结束日期", null).toJson();
		}
		Map<String, Integer> totalData = hotelDataService.getNewHotelDataGroupDate(startTime,endTime,areaCode);
		List<Date> allDate = DateUtil.getBetweenDates(DateUtil.parseYMD(startTime), DateUtil.parseYMD(endTime));
		for(Date date : allDate){
			Integer count = (Integer) totalData.get(DateUtil.formatYMD(date));
			if(count == null){
				totalData.put(DateUtil.formatYMD(date),0);
			}
		}
		return new ResponseWrapTo(0, "数据获取成功", totalData).toJson();
	}
	
	
}
